package com.yogee.topseller.activity.my;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.yogee.core.base.HttpActivity;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.adapter.NoticeRvAdapter;
import com.yogee.topseller.bean.MessageInfoBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;

import butterknife.BindView;

public class NoticeActivity extends HttpActivity {

    @BindView(R.id.notice_title_layout)
    TitleLayout titleLayout;
    @BindView(R.id.notice_rv)
    RecyclerView noticeRv;
    private NoticeRvAdapter adapter;

    private int type;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_notice;
    }

    @Override
    protected void initView() {
        type = getIntent().getIntExtra("type", 0 );
        switch (type) {
            case 0:
                titleLayout.setTitle("系统消息");
                break;
            case 1:
                titleLayout.setTitle("服务动态");
                break;
            case 2:
                titleLayout.setTitle("通知消息");
                break;
        }

        titleLayout.setActivity(this);
        adapter = new NoticeRvAdapter(this, type);
        noticeRv.setHasFixedSize(true);
        noticeRv.setLayoutManager(new LinearLayoutManager(this));
        noticeRv.setAdapter(adapter);

        genMessageInfo(AppUtil.getUserId(this), String.valueOf(type));
    }

    private void genMessageInfo(String userId, String type) {
        HttpManager.getInstance().genMessageInfo(type, userId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<MessageInfoBean>() {
            @Override
            public void onNext(MessageInfoBean o) {
                adapter.addData(o.getMessage());
            }
        }, this));
    }
}